/*
 * graphics.h
 *
 *  Created on: 09 Nis 2012
 *      Author: hframe
 */

#ifndef GRAPHICS_H_
#define GRAPHICS_H_

#include <EGL/egl.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <android/native_window.h>
#include <map>
#include <math.h>
#include "../common.h"
#include "../drawing/color.h"
#include "../drawing/matrix.h"




startnamespace( androidplus)
startnamespace(ui)

class graphics {
public:
	graphics(ANativeWindow *window);
	virtual ~graphics();
public:
	   t_int32 get_height();
	   t_int32 get_width();
	   void flush();
	   void draw_background(drawing::color c);
	   GLint create_program(const char *program_name, const char*vertex,const char*fragment);
public:
	   drawing::matrix frustum(t_float left,t_float right,t_float bottom, t_float top, t_float nearZ, t_float farZ);
	   drawing::matrix perspective(t_float fovy, t_float aspect, t_float nearZ, t_float farZ);
	   drawing::matrix ortho(t_float left, t_float right, t_float bottom, t_float top, t_float farZ, t_float nearZ);
	   drawing::matrix lookat(t_float eyeX, t_float eyeY,t_float eyeZ  , t_float centerX  , t_float centerY  , t_float centerZ , t_float upX  , t_float upY , t_float upZ);
       drawing::matrix *projection_matrix;
       drawing::matrix *camera_matrix;
       drawing::matrix *model_matrix;
       static t_int32 is_projection_matrix_loaded;
       static t_int32 is_transformation_matrix_loaded;
protected:
     EGLDisplay  display;
     EGLSurface surface;
     EGLContext context;
private:
     t_int32  initialize();
     void uninitialize();
    ANativeWindow  *native_window;
    t_int32  surface_width;
    t_int32  surface_height;
    void check_error(const char *msg);
    GLuint load_shader(const char * src,GLenum type);
private:
    std::map<t_string, GLint> program_objects;
};

endnamespace(ui)
endnamespace(androidplus)
#endif /* GRAPHICS_H_ */
